<?php

cload("database.dbrow");
cload("database.dbquery");

/**
 * Description of advRatingConvertor
 *
 * @author Di_Moon
 */
class advRatingConvertor extends dbrow {
    protected $_haveRow = false;
    
    function __construct($dbh, $country) {
        parent::__construct($dbh, "advRatingConvertor");
        $this->set("country", $country);
    }
    
    function load($rating=null) {
        $sql = new dbquery($this->_dbh);
        $sql->select()->from($this->_prfxtable)->where("rating='".$rating."' and country='".$this->get("country")."'");
        $sth = $this->_dbh->query($sql);
        
        if($fa=$this->_dbh->raw_fetch_array($sth)) {
            $this->_haveRow = true;
            $row = $this;
            $row->setElements($fa);
            
            return $row;
        }
        
        return null;
    }
    
    function save($index=null) {
        $sql = new dbquery($this->_dbh);
        if($this->_haveRow) {
            $sql->update($this->_prfxtable)
                    ->field("converted", $this->get("converted"))
                    ->field("type", $this->get("type"))
                    ->where("rating='".$this->get("rating")."' and country='".$this->get("country")."'");
        } else {
            $sql->insert()->into($this->_prfxtable)
                    ->field("converted", $this->get("converted"))
                    ->field("type", $this->get("type"))
                    ->field("rating", $this->get("rating"))
                    ->field("country", $this->get("country"));
            
        }
        $this->_dbh->query($sql);
    }
}

?>
